<template>
  <a-modal title="项目信息" :visible="show" @ok="handleOk" @cancel="handleCancel" width="70vw" :maskClosable="false">
    <div>
      <a-button @click="fetchList" icon="search" class="hte-btn">刷新</a-button>
    </div>
    <div style="height: 360px; overflow: scroll">
      <a-table
        :scroll="{ y: 300 }"
        :columns="listColumns"
        :data-source="records"
        :rowKey="(record,index)=>{
          return index
        }"
        bordered
        :pagination="false"
        :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
      >
      </a-table>
    </div>
  </a-modal>
</template>
<script>
import { postAction } from '@/api/manage'
export default {
  components: {},
  props: {
    show: {
      type: Boolean,
      default: false,
    },
    supplierCode: {
      type: String,
      default: null,
    },
    wbs: {
      type: String,
      default: null,
    },
  },
  data() {
    return {
      listColumns: [
        {
          title: '采购订单号',
          dataIndex: 'EBELN',
          width: '100px',
          align: 'center',
        },
        {
          title: '合同号',
          dataIndex: 'DOKNR',
          width: '200px',
          align: 'center',
        },
        {
          title: '合同名称',
          dataIndex: 'contractName',
          width: '250px',
          align: 'center',
        },
      ],
      urls: {
        loadPurchaseOrderList: '/hte/contract/loadPurchaseOrderList',
      },
      selectedRowKeys: [],
      selectedRow: [],
      records: [],
    }
  },
  mounted() {
    this.fetchList()
  },
  methods: {
    fetchList() {
      let param = {}
      param.supplierCode = this.supplierCode
      param.wbs = this.wbs
      postAction(this.urls.loadPurchaseOrderList, param).then((res) => {
        if (res.success) {
          this.records = res.result
        }
      })
    },
    onSelectChange(selectedRowKeys, selectedRow) {
      this.selectedRowKeys = selectedRowKeys
      this.selectedRow = selectedRow
    },
    handleOk() {
      this.$emit('selected', this.selectedRow)
    },
    handleCancel() {
      this.$emit('selected', [])
    },
  },
}
</script>
<style lang="less" scoped>
@import '~@assets/less/hte-main.less';
.page-main {
  .container {
    .content {
      margin-top: 20px;
      section {
        .section-table {
          .add-btn {
            margin-left: 0;
            margin-bottom: 10px;
          }
        }
      }
    }
  }
  .tips-box {
    margin-top: 32px;
    .add-btn {
      width: 180px;
      height: 40px;
      line-height: 40px;
      background-color: #4095e4;
      border-radius: 2px;
    }
  }
}
.icon-file {
  background-image: url('~@assets/file.png');
}
.cr-content-pop {
  p {
    margin-bottom: 15px;
    color: #666;
    &:last-child {
      margin-bottom: 0;
    }
  }
}
</style>